/*
 * @Description:  将页面PageContextProps属性全局注入 (provide & inject)
 * @Author: wangqi
 * @Date: 2024-05-11 10:17:29
 * @LastEditTime: 2024-06-15 11:52:01
 * @LastEditAuthor: wangqi
 */
import type { InjectionKey, ComputedRef, Ref } from 'vue';
import { createContext, useContext } from '@/hooks/core/useContext';

export interface PageContextProps {
  contentHeight: ComputedRef<number>;
  pageHeight: Ref<number>;
  setPageHeight: (height: number) => Promise<void>;
}

const key: InjectionKey<PageContextProps> = Symbol();

/* 创建页面内容高度属性 provide */
export function createPageContext(context: PageContextProps) {
  return createContext<PageContextProps>(context, key, { native: true });
}

/* 使用页面内容高度属性 inject */
export function usePageContext() {
  return useContext<PageContextProps>(key);
}
